#ifndef SHUTTLE_H
#define SHUTTLE_H

#include "scene.h"
#include "consts.h"
#include "collisia_control.h"
#include "cash.h"
#include "shuttle_shield.h"
#include "hud.h"
#include "sdl_gamepad.h"
#include "sprite_ship_base.h"

class Shuttle : public QObject, public QGraphicsItemGroup
{
    Q_OBJECT
private:
    SPRITE_SHIP_BASE *sprite_ship;

//gatlings
    GRAPHICS_PIXMAP_ITEM *item_gatling_1;
    GRAPHICS_PIXMAP_ITEM *item_gatling_2;

    QGraphicsItemAnimation *anim_gatling_1;
    QGraphicsItemAnimation *anim_gatling_2;

    QTimeLine *time_line_gatlings;

//cannons
    GRAPHICS_PIXMAP_ITEM *item_cannon_1;
    GRAPHICS_PIXMAP_ITEM *item_cannon_2;

    QGraphicsItemAnimation *anim_cannon_1;
    QGraphicsItemAnimation *anim_cannon_2;

    QTimeLine *time_line_cannons;

//анимации полета корабля
    QTimeLine *tl_anim_ship;
    int dx;
    int dy;
    bool flag_tl_started;
    int fly_step;


//массив нажатых клавиш
    QSet<int> *set_keys;

//флаги и настройки
    bool flag_anim_gatling;
    bool flag_anim_cannon;

    bool cannons_state;

//последняя нажатая клавиша
    int last_key;
    int last_fire_key;

//shield
    SHUTTLE_SHIELD *shield;

//hud
    HUD *hud;

    int point;

    QString str_state;

//GAMEPAD Thread
    SDL_GAMEPAD *gamepad;

public:
    QPainterPath *border;
    QPainterPath *shield_border;

    COLLISIA_CONTROL *collisia_control;

    CASH *cash;

    int timer_id;

    SCENE *scene;

    SOUND_POWER *sound_fireboll;
    SOUND_POWER *gun;
    SOUND_POWER *damage_sound;

public:
    Shuttle(SCENE *scene, QTimeLine *global_tl,CASH *cash, HUD *hud);

    void init();
    void anim_init();
    void align();

    void debug_set_keys();
    QSet<int> *get_set_keys();

    void timerEvent(QTimerEvent *);

    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);

    void init_anim_fly();
    void init_anim_gatling();
    void init_anim_cannon();

    QRectF boundingRect() const;

    QPainterPath shape() const;

    int type() const;

    void set_points(int value);

    void cannons_visible(bool value);

    bool Get_Cannons_State();

    ~Shuttle();

signals:
    void signal_keys_pressed();
    void signal_keys_released();

    void signal_fly(MOVE_DIRECTION);
    void signal_fly_finish();
    void signal_fly_finish(MOVE_DIRECTION);

    void signal_fire_start(WEAPON_TYPE);
    void signal_fire_finish(WEAPON_TYPE);

    void signal_transform(QString, QString);

    void Uuuups_I_die();

public slots:
    void slot_gatling_released();
    void slot_cannon_released();

    void slot_shuttle_fly();
    void slot_shuttle_fly_released();

    void slot_tl_changed();

    void slot_fire_start();
    void slot_fire_end();

    void Damage_Detected(QPointF a,int d);

    void simulate_damage();
    void start_mission_anim();

    void slot_fake_start_left();
    void slot_fake_start_right();

    void slot_gamepad_clicked(GAMEPAD_ACTION action);
    void slot_gamepad_released(GAMEPAD_ACTION action);

    void slot_transform_to_speedboat();
    void slot_transform_to_shuttle();
    void slot_transform_to_submarine();

};

#endif // SHUTTLE_H
